export function tpl(){
    return `
import React, { useContext } from 'react';
const AccessContext = React.createContext({});

//Provider
export function AccessProvider({ children, permissions }: any) {

  //根据code判断权限
  const check = (code: string) => {
    return !!permissions?.[code];
  };

  return (
    <AccessContext.Provider value={{ check, permissions}}>
      {children}
    </AccessContext.Provider>
  );
}

export function useAccess(): any {
  const value = useContext(AccessContext);
  return value;
}

export function Access({ fallback, children, code }: any) {
  const { check } = useAccess();

  if (!check(code)) {
    return fallback ? fallback : null;
  }

  return children;
}`
}

